﻿using System;
using System.Collections.Generic;
using System.Text;
using Vortex.Wrapper.Direct3D;

namespace Vortex.Drawing {

	/// <summary>
	/// Base class for device components. It handles component creation and management 
	/// </summary>
	abstract class Component : DeviceListener, IDisposable {
		protected DrawingDevice _device;
		protected Direct3DDevice9 _d3dDevice;

		protected Component(DrawingDevice device) {
			_device = device;
			_d3dDevice = device.ApiRef;
			base.StartListeningDevice(_device);
		}

		/// <summary>
		/// Gets the device instance for this component.
		/// </summary>
		/// <value>The device instance.</value>
		public DrawingDevice Device {
			get { return _device; }
		}

		#region Component Management

		/// <summary>
		/// Destroys component. Frees the internal data of component.
		/// </summary>
		public virtual void Destroy() { }

		#endregion

		#region IDisposable Members

		/// <summary>
		/// Performs freeing unmanaged resources related to device.
		/// </summary>
		public void Dispose() {
			base.StopListeningDevice(_device);
			Destroy();
		}

		#endregion

	}

}
